<!-- 任务 views/Personal.vue -->
<template>
  <tMain>
    <template slot="content">
      <van-row class="header">
        <van-col span="4">
          <img class="avatar" width="60" src="../assets/images/avatar.jpg" />
        </van-col>
        <van-col class="userInfo" span="16">
          <div class="nameBox">
            <span class="name">{{ userInfo.userInfoName }}</span
            ><span class="phone">{{ userInfo.userInfoPhone }}</span>
          </div>
          <p class="company">
            <van-icon class="icon" name="hotel-o" />{{ userInfo.companyName }}
          </p>
          <p class="organization">
            <van-icon class="icon" name="friends-o" />{{ userInfo.orgName }}
          </p>
        </van-col>
        <van-col v-if="role === 'outworker'" class="status" span="4">
          <p>{{ this.checked ? '接单中' : '休息中' }}</p>
        </van-col>
      </van-row>
      <van-grid class="count" :border="false" :column-num="5">
        <van-grid-item>
          <p>{{ count.totalCount }}</p>
          <span>总数</span>
        </van-grid-item>
        <van-grid-item>
          <p>{{ isOutWorker ? count.receiveCount : count.publishedCount }}</p>
          <span>{{isOutWorker?'已接单':'已发布'}}</span>
        </van-grid-item>
        <van-grid-item>
          <p>{{ count.passedCount }}</p>
          <span>已通过</span>
        </van-grid-item>
        <van-grid-item>
          <p>{{ count.failedCount }}</p>
          <span>未通过</span>
        </van-grid-item>
        <van-grid-item>
          <p>{{isOutWorker ? count.rejectionCount : count.rejectedCount }}</p>
          <span>拒单</span>
        </van-grid-item>
      </van-grid>
      <div class="block">
        <van-cell v-if="isOutWorker" icon="shop-o" title="接单">
          <template #right-icon>
            <van-switch v-model="checked" size="24" />
          </template>
        </van-cell>
      </div>
      <div class="block">
        <van-cell icon="edit" title="修改密码" is-link to="/modifyPwd" />
        <van-cell icon="service-o" title="联系客服" is-link to="" />
      </div>
      <div class="block">
        <van-cell icon="shop-o" title="退出登录" @click="signOut" is-link />
      </div>
    </template>
  </tMain>
</template>
<script>
import tMain from '@/components/templete/main.vue'
import { mapGetters, mapState } from 'vuex'
import { Dialog } from 'vant'
export default {
  data() {
    return {
      count: {},
      checked: true
    }
  },
  components: {
    tMain
  },
  computed: {
    ...mapState(['userInfo']),
    ...mapGetters(['role']),
    isOutWorker(){
      return this.role === 'outworker'
    }
  },
  methods: {
    getCount() {
      let url = this.isOutWorker ? '/api/worker/outworkerStatistic':'/api/manager/findManagerStatistics'
      this.axios(url)
        .then(res => {
          console.log(res.data.data)
          this.count = res.data.data
        })
        .catch(errr => {
          console.log(err)
        })
    },
    signOut() {
      Dialog.confirm({
        title: '提示',
        message: '确定要退出吗？'
      })
        .then(() => {
          localStorage.clear()
          this.$router.push('/login')
        })
        .catch(() => {
          // on cancel
        })
    }
  },
  mounted() {
    this.getCount()
  }
}
</script>
<style lang="less" scoped>
.header {
  display: flex;
  align-items: center;
  color: white;
  text-align: left;
  padding-top: 50px;
  padding-left: @padding-md;
  .userInfo {
    padding: 0 @padding-md;
    .nameBox {
      margin-bottom: @padding-xs;
    }
    .name {
      font-weight: @font-weight-bold;
      padding-right: @padding-sm;
    }
    .phone {
      font-size: @font-size-sm;
    }
    .icon {
      top: 2px;
      padding-right: @padding-xs;
    }
  }
  p {
    font-size: @font-size-sm;
  }
  .status {
    height: 25px;
    line-height: 25px;
    text-align: center;
    background: #ffffff;
    color: @main-color;
    border-radius: 13px 0 0 13px;
  }
}
.count {
  margin: @padding-sm;
  border-radius: @border-radius-md;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(125, 126, 128, 0.06);
  background: #fff;
  p {
    font-size: @font-size-xs*2;
    font-weight: @font-weight-bold;
    color: @main-color;
  }
  span {
    font-size: @font-size-sm;
  }
}
.block {
  margin-top: @padding-sm;
  box-shadow: 0 0px 10px rgba(125, 126, 128, 0.06);
}
.avatar {
  border-radius: 50%;
}
</style>
